package controllers;

import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import util.BrowserType;
import util.HttpUtils;

import java.util.Map;

public class Application extends Controller {

    public static Result index() {
        BrowserType browserType = getBrowserType();
        Status ok;
        switch (browserType) {
            case mobile:
                ok = ok(views.html.mobile.index.render("Your new application is ready."));
                break;
            case smartphone:
                ok = ok(views.html.smartphone.index.render("Your new application is ready."));
                break;
            default:
                ok = ok(views.html.web.index.render("Your new application is ready."));
                Http.Session session = Http.Context.current().session();
                session.put("Browser_d", "web");
                break;
        }
        return ok;
    }

    private static BrowserType getBrowserType() {
        Http.Request req = Http.Context.current().request();
        Map<String, String[]> headerMap = req.headers();
        return HttpUtils.getBrowserType(headerMap);
    }

    public static Result about() {
        BrowserType browserType = getBrowserType();
        Status ok;
        switch (browserType) {
            case mobile:
                ok = ok(views.html.mobile.about.render("Your new application is ready."));
                break;
            case smartphone:
                ok = ok(views.html.smartphone.about.render("Your new application is ready."));
                break;
            default:
                ok = ok(views.html.web.about.render("Your new application is ready."));
                Http.Session session = Http.Context.current().session();
                session.put("Browser_d", "web");
                break;
        }
        return ok;
    }

    public static Result services() {
        BrowserType browserType = getBrowserType();
        Status ok;
        switch (browserType) {
            case mobile:
                ok = ok(views.html.mobile.services.render("Your new application is ready."));
                break;
            case smartphone:
                ok = ok(views.html.smartphone.services.render("Your new application is ready."));
                break;
            default:
                ok = ok(views.html.web.services.render("Your new application is ready."));
                Http.Session session = Http.Context.current().session();
                session.put("Browser_d", "web");
                break;
        }
        return ok;
    }

    public static Result contact() {
        BrowserType browserType = getBrowserType();
        Status ok;
        switch (browserType) {
            case mobile:
                ok = ok(views.html.mobile.contact.render("Your new application is ready."));
                break;
            case smartphone:
                ok = ok(views.html.smartphone.contact.render("Your new application is ready."));
                break;
            default:
                ok = ok(views.html.web.contact.render("Your new application is ready."));
                Http.Session session = Http.Context.current().session();
                session.put("Browser_d", "web");
                break;
        }
        return ok;
    }

    public static Result single() {
        BrowserType browserType = getBrowserType();
        Status ok;
        switch (browserType) {
            case mobile:
                ok = ok(views.html.mobile.single.render("Your new application is ready."));
                break;
            case smartphone:
                ok = ok(views.html.smartphone.single.render("Your new application is ready."));
                break;
            default:
                ok = ok(views.html.web.single.render("Your new application is ready."));
                Http.Session session = Http.Context.current().session();
                session.put("Browser_d", "web");
                break;
        }
        return ok;
    }

    public static Result error404() {
        BrowserType browserType = getBrowserType();
        Status ok;
        switch (browserType) {
            case mobile:
                ok = ok(views.html.mobile.error404.render("Your new application is ready."));
                break;
            case smartphone:
                ok = ok(views.html.smartphone.error404.render("Your new application is ready."));
                break;
            default:
                ok = ok(views.html.web.error404.render("Your new application is ready."));
                Http.Session session = Http.Context.current().session();
                session.put("Browser_d", "web");
                break;
        }
        return ok;
    }
}
